package com.apac.services;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.Set;
import java.util.TreeMap;

import com.apac.dao.JmesaColumnsDAO;
import com.apac.delegates.EmployeeDelegate;
import com.apac.jmesa.JmesaTableColumnNames;

public class JmesaObjectGenerator {

	public static TreeMap<String, Object> generateJmesaEmployee(EmployeeDelegate emp) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException{
		TreeMap<String, Object> empMap = new TreeMap<String, Object>();
		
		JmesaColumnsDAO jDao = new JmesaColumnsDAO();

		TreeMap<String,String> methodMap = jDao.findMethodByTableId(JmesaTableColumnNames.RESOURCE_TRACKER_INFO);
		
		
		Set<String> keys = methodMap.keySet();
		
		for(String key:keys){
			String methodName = methodMap.get(key);
			Method method = null;
			try {
				method = EmployeeDelegate.class.getDeclaredMethod(methodName);
			} catch (NoSuchMethodException e) {
				System.out.println(methodName);
				e.printStackTrace();
			} catch (SecurityException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			Object value = method.invoke(emp);
			
			empMap.put(key, value);
			
		}
		
		return empMap;
	}
	
}
